package com.ny.demo2;
abstract class Insurance {
    public abstract double calculatePremium();
}

class CarInsurance extends Insurance {
    private double carValue;
    private int accidentCount;

    public CarInsurance(double carValue, int accidentCount) {
        this.carValue = carValue;
        this.accidentCount = accidentCount;
    }

    @Override
    public double calculatePremium() {
        double basePremium = carValue * 0.02;
        if (accidentCount == 0) {
            return basePremium;
        } else if (accidentCount == 1) {
            return basePremium * 1.1;
        } else {
            return basePremium * 1.2;
        }
    }
}


class HomeInsurance extends Insurance {
    private double houseValue;
    private int houseArea;

    public HomeInsurance(double houseValue, int houseArea) {
        this.houseValue = houseValue;
        this.houseArea = houseArea;
    }

    @Override
    public double calculatePremium() {
        double basePremium = houseValue * 0.015;
        if (houseArea > 100) {
            return basePremium * 1.05;
        }
        return basePremium;
    }
}

public class InsuranceTest {
    public static void main(String[] args) {
        CarInsurance carInsurance = new CarInsurance(100000, 1);
        System.out.println("车险保费: " + carInsurance.calculatePremium());

        HomeInsurance homeInsurance = new HomeInsurance(2000000, 120);
        System.out.println("家庭基本险保费: " + homeInsurance.calculatePremium());
    }
}
